name: Build and publish release packages
permissions:
  contents: write
on:
  release:
    # 'published' is triggered when publishing draft release, 'created' is not
    types: [published]

jobs:
  build-linux-binaries:
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
    runs-on: ${{ matrix.os }}
    steps:
      - name: Install dependencies
        run: |
            sudo apt-get update
            sudo apt-get install -y gcc-multilib clang cmake protobuf-compiler
      - uses: actions/checkout@v4
      - name: Build and publish
        uses: taiki-e/upload-rust-binary-action@v1
        with:
          bin: qdrant
          target: ${{ matrix.target }}
          token: ${{ secrets.GITHUB_TOKEN }}

  build-mac-binaries:
    strategy:
      matrix:
        include:
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: aarch64-apple-darwin
            os: macos-latest
    runs-on: ${{ matrix.os }}
    steps:
      - name: Install dependencies
        run: |
            brew update-reset
            brew install gcc cmake protobuf-c
      - uses: actions/checkout@v4
      - name: Build and publish
        uses: taiki-e/upload-rust-binary-action@v1
        with:
          bin: qdrant
          target: ${{ matrix.target }}
          token: ${{ secrets.GITHUB_TOKEN }}

  build-windows-binaries:
    strategy:
      matrix:
        include:
          - os: windows-latest
    runs-on: ${{ matrix.os }}
    steps:
      - name: Install minimal stable
        uses: dtolnay/rust-toolchain@stable 
      - uses: actions/checkout@v4
      - uses: Swatinem/rust-cache@v2
      - name: Install Protoc
        uses: arduino/setup-protoc@v2
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Build
        run: cargo build --release --locked

      - name: Build and publish
        uses: taiki-e/upload-rust-binary-action@v1
        with:
          bin: qdrant
          token: ${{ secrets.GITHUB_TOKEN }}
